﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Torimi.Wiki.DataObjects;

namespace Torimi.Wiki.Web.ContentManagement
{
	public partial class AddWikiPage : System.Web.UI.UserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			ddlCategories.DataSource = Services.WikiInstance.GetAllCategories();
			ddlCategories.DataBind();
		}

		protected void btnAdd_Click(object sender, EventArgs e)
		{
			var wikiPage = new DataObjects.WikiPage
			{
				Id = Guid.NewGuid(),
				Name = txtName.Text,
				Title = txtTitle.Text,
				Content = txtContent.Text,
				CategoryId = new Guid(ddlCategories.SelectedValue)
			};

			Services.WikiInstance.AddPage(wikiPage);

			ResetFields();
		}

		private void ResetFields()
		{
			txtContent.Text = string.Empty;
			txtName.Text = string.Empty;
			txtTitle.Text = string.Empty;
		}
	}
}